package com.hyts.infodb.zuul.service;

import com.hyts.infodb.zuul.bean.ZuulRoutePO;
import com.hyts.infodb.zuul.bean.ZuulRouteVO;
import com.hyts.infodb.zuul.dao.ZuulDAO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * project-name:infodb
 * package-name:com.hyts.infodb.zuul.service
 * author:Libo/Alex
 * create-date:2019-05-22 20:54
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: zuul 路由服务业务逻辑对象实体业务类
 */
@Service
public class ZuulService {



    @Autowired
    ZuulDAO zuulDAO;

    /**
     * 获取所有的路由信息存储在db中的
     * @return
     */
    public List<ZuulProperties.ZuulRoute> findAllRoute(){
        List<ZuulRoutePO> zuulRoutePOList = zuulDAO.findAll();
        if(zuulRoutePOList != null){
            return zuulRoutePOList.parallelStream().map(param-> {
               ZuulProperties.ZuulRoute zuulRoute = new ZuulProperties.ZuulRoute();
               BeanUtils.copyProperties(param,zuulRoute);
               zuulRoute.setId(param.getId()+"");
               return zuulRoute;
            }).collect(Collectors.toList());
        }
        return null;
    }

}
